package com.derive.education_service.web.notice.controller;

import com.derive.education_service.common.global.Paper;
import com.derive.education_service.common.global.ResponseMessage;
import com.derive.education_service.entity.Notice;
import com.derive.education_service.web.notice.bean.dto.NoticeAddDto;
import com.derive.education_service.web.notice.bean.dto.NoticeUpDto;
import com.derive.education_service.web.notice.bean.dto.QueryParam;
import com.derive.education_service.web.notice.service.NoticeService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

/**
 * 通告操作接口
 */
@RestController
@RequestMapping("notice")
@Slf4j
@Validated
public class NoticeController {

    @Autowired
    private NoticeService noticeService;

    /**
     * 发布通告 -- 有上传文件就提交文件
     * @param file
     * @param noticeAddDto
     * @return
     */
    @PostMapping("addNotice")
    public ResponseMessage addNotice(@RequestPart("file") MultipartFile file, @Validated @RequestPart("noticeAddDto") NoticeAddDto noticeAddDto) {
        return noticeService.addNotice(file, noticeAddDto);
    }

    /**
     * 编辑通告
     * @param file
     * @param noticeUpDto
     * @return
     */
    @PostMapping("upNotice")
    public ResponseMessage upNotice(@RequestPart("file") MultipartFile file, @Validated @RequestPart("noticeUpDto") NoticeUpDto noticeUpDto) {
        return noticeService.upNotice(file, noticeUpDto);
    }

    /**
     * 删除通告 -- 有资源删除资源
     * @param noticeId
     * @return
     */
    @PostMapping("delNotice")
    public ResponseMessage delNotice(int noticeId) {
        return noticeService.delNotice(noticeId);
    }

    /**
     * 查询通告详情
     * @param noticeId
     * @return
     */
    @GetMapping("getNoticeById")
    public ResponseMessage getNoticeById(int noticeId) {
        return noticeService.getNoticeById(noticeId);
    }

    /**
     * 检索通告信息 -- 分页查询 -- 条件查询
     * @param queryParam
     * @return
     */
    @PostMapping("getNoticeList")
    public ResponseMessage getNoticeList(@RequestBody @Validated QueryParam queryParam) {
        Paper<Notice> paper = noticeService.getNoticeList(queryParam);
        return ResponseMessage.createBySuccess(paper);
    }
}
